// Ray Bai
// Creating a Telephone Directory in C++
// 5/31/2011

#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
    char name[50];
    char telnum[12];
    int selection;
    
    ofstream outfile("C:\\Users\\Ray Bai\\Programming\\directory.txt");
    if(!outfile) {
                 cerr << "Output file could not be created" << endl;
                 exit(1);
                  }
   
    do {
    // Display the menu and allow user to choose 1 or 2.
        cout << endl << endl;
        cout << "\t1. Update telephone directory.\n";
        cout << "\t2. Quit program. \n\n";
        cout << "\tEnter your choice (1-2): ";
        cin >> selection;
        
    // Validate menu selection.
    if (selection < 1 || selection > 2)
    {
    cout << endl;
    cout << "\n\n\t**Error: Menu option must be 1 or 2.\n\n";
    }
    else if (selection == 1)
    {
        cout << "\t Enter name: ";            
        cin.getline(name, 50);
        cout << endl << "\n\t Enter telephone #: ";
        cin.getline(telnum, 12);
        outfile << setw(30) << right << name << "\t\t\t";
        // << setw(13) << right << telnum << endl;
        cout << "\n\n\t Record stored. \n\n";
    }
    else if (selection == 2) // Quit program
    {         
         cout << "\n\n You have now exited the program. \n\n";
    }
    }while(selection != 2);

    system("pause");
    return 0;
}
